// https://leetcode.cn/problems/valid-perfect-square/
// Created by ade on 2022/8/3.
//
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>

using namespace std;

class Solution {
public:
    // 暴力法超时
    bool isPerfectSquare1(int num) {
        int tail = num % 10;
        if (tail == 2 || tail == 3 || tail == 7 || tail == 8) return false;
        map<int, vector<int>> vMap = {};
        vMap[1] = {1, 9};
        vMap[4] = {2, 8};
        vMap[9] = {3, 7};
        vMap[6] = {4, 6};
        vMap[5] = {5};
        vMap[0] = {0};
        int mid = num / 2;
        for (int i = 0; i <= mid; i = i + 10) {
            for (auto j : vMap[tail]) {
                if ((i + j) * (i + j) == num) {
                    return true;
                }
            }
        }
        return false;
    }

    // 二分法更快
    bool isPerfectSquare(int num) {
        int tail = num % 10;
        if (tail == 2 || tail == 3 || tail == 7 || tail == 8) return false;
        int left = 0, right = num / 2 + 2;
        while (left < right) {
            int mid = (left + right) / 2;
            if ((long long)mid * mid == (long long)num) return true;
            if ((long long)mid * mid < (long long)num) {
                left = mid + 1;
            } else {
                right = mid;
            }
        }
        return false;

    }
};

int main() {
    Solution so;
    int a = 257;
    if (so.isPerfectSquare(a))
        cout << "yes" << endl;
    else
        cout << "no" << endl;
    return 0;
}